package org.scripts.watcher.gui;

import org.farming.Patches;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.ArrayList;

public class WatcherFrame extends JFrame 
{
   
    public WatcherFrame()
    {
        initComponents();
    }
    public void update()
    {
        for (PatchPanel pp : patchPanels)
        {//Dynamically iterate every pp and update its details
            pp.update();
        }
    }
    private void initComponents() 
    {
        //Define layout manager
        this.setLayout(new GridLayout(0, 2, 5, 5));//x rows, 2 columns, margins of 5 between cells
        //Create, log and add to layout all the patch panels
        ArrayList<PatchPanel> patchPanelsAL = new ArrayList<PatchPanel>(); 
        for (Patches patch : Patches.values())
        {//Dynamically iterate every patch in the enum Patches
            PatchPanel pp = new PatchPanel(patch); //Create the patch panel
            patchPanelsAL.add(pp);//Add the pp to our AL
            this.add(patch.toString(), pp);//Add the pp to the layout/gui
        }
        patchPanels = new PatchPanel[patchPanelsAL.size()];//Setup the array
        patchPanelsAL.toArray(patchPanels);//Dump AL to array
        this.pack();//Resize the gui to tightly fit the content
        setVisible(true);//Display form
    }
    private PatchPanel[] patchPanels;
}